package com.android.boncen.commonFrame.fragment;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;

import com.android.boncen.commonFrame.R;

/**
 * 功能描述:添加血压
 *
 * @date 2017/2/9
 */

public class AddBMIDialog extends AlertDialog {

    private EditText etSG;
    private EditText etTZ;

    public AddBMIDialog(Context context, SaveCallback callback) {
        super(context, R.style.CustomDialogStyle);
        this.callback = callback;
    }

    public interface SaveCallback {
        void save(float gy);
    }

    SaveCallback callback;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.popupwindow_bmi);
        getWindow().clearFlags(
                WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        etSG = (EditText) findViewById(R.id.etSG);
        etTZ = (EditText) findViewById(R.id.etTZ);
        findViewById(R.id.popup_bt_save).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                save(etSG.getText().toString(), etTZ.getText().toString());
            }
        });

    }

    private void save(String gy, String dy) {
        if (TextUtils.isEmpty(gy)) {
            Toast.makeText(getContext(), "身高不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (TextUtils.isEmpty(dy)) {
            Toast.makeText(getContext(), "体重不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        float bmi = Float.valueOf(dy)/((Float.valueOf(gy)/100)*(Float.valueOf(gy)/100));

        dismiss();
        callback.save(bmi);

    }
}
